package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.modular.system.entity.KmsApp;
import cn.stylefeng.guns.sys.modular.system.service.KmsAppService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/kmsApp")
public class KssAppController extends BaseController {

    @Autowired
    KmsAppService kmsAppService;

    private String PREFIX = "/modular/system/kmsApp/";


    @RequestMapping("/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) Integer index,
                       @RequestParam(required = false) String backId) {
        //获取分页参数
        Page<Map<String, Object>> mapPage = kmsAppService.selectKmsApp();
        return LayuiPageFactory.createPageInfo(mapPage);
    }

    /**
     *
     *
     * @author fengshuonan
     * @Date 2018/12/23 4:56 PM
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "kmsApp.html";
    }



    /**
     *
     *
     * @author fengshuonan
     * @Date 2018/12/23 4:56 PM
     */
    @RequestMapping("/toAdd")
    public String toAdd() {
        return PREFIX + "kmsApp_add.html";
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public ResponseData add(@RequestParam String name) {
        kmsAppService.add(name);
        System.out.println("");
        return SUCCESS_TIP;
    }


    @GetMapping("/getAll")
    @ResponseBody
    public ResponseData getAll() {
        List<KmsApp> all = kmsAppService.getAll();
        return ResponseData.success(all);
    }

    @GetMapping("/getAppInfo")
    @ResponseBody
    public ResponseData getAppInfo(@RequestParam String token) {
        QueryWrapper<KmsApp> srcwrapper = new QueryWrapper<>();
        srcwrapper.eq("token", token);
        KmsApp kmsApp = kmsAppService.getOne(srcwrapper);
        return ResponseData.success(kmsApp);
    }
}
